<template>
	<view class="container">
		<view class="list-cell-section icon">
			<view class="zy-head" >
				<view class="zy-head-title">余额</view>
				<view class="zy-head-extra" @click="toWithdrawList">提现记录</view>
			</view>
			<view class="zy-list-cell b-b m-t" hover-class="cell-hover" :hover-stay-time="50">
				<text  class="cell-tit">总余额</text>
				<text class="cell-content">{{userWallet.usableRmbBalance.toFixed(2)}}</text>
			</view>
			<view class="zy-list-cell b-b m-t" hover-class="cell-hover" :hover-stay-time="50">
				<text v-if="code==3" class="cell-tit">可提现余额</text>
				<text v-else class="cell-tit">可用余额</text>
				<text class="cell-content">{{available}}</text>
			</view>
			<view class="zy-list-cell b-b m-t" hover-class="cell-hover" :hover-stay-time="50">
				<text v-if="code==3" class="cell-tit">待审核金额</text>
				<text v-else class="cell-tit">冻结余额</text>
				<text class="cell-content">{{(userWallet.usableRmbBalance - available).toFixed(2)}}</text>
			</view>
		</view>
		<!-- <view class="list-cell-section icon">
			<view class="zy-head" >
				<view class="zy-head-title">积分</view>
			</view>
			<view class="zy-list-cell b-b m-t" hover-class="cell-hover" :hover-stay-time="50">
				<text class="cell-tit">总积分</text>
				<text class="cell-content">{{userWallet.integral}}</text>
			</view>
			<view class="zy-list-cell b-b m-t" hover-class="cell-hover" :hover-stay-time="50">
				<text class="cell-tit">可用积分</text>
				<text class="cell-content">{{userWallet.usableIntegral}}</text>
			</view>
			<view class="zy-list-cell b-b m-t" hover-class="cell-hover" :hover-stay-time="50">
				<text class="cell-tit">冻结积分</text>
				<text class="cell-content">{{userWallet.frozenIntegral}}</text>
			</view>
		</view> -->
		
		<button v-if="code==3" class="zy-add-btn" @click="toWithdraw">余额提现</button>
	</view>
</template>

<script>
	import * as ResponseStatus from '@/common/response-status.js'
	import { showInfoToast } from '@/common/util.js'
	import zyworkIcon from '@/components/zywork-icon/zywork-icon.vue'
	import listCell from '@/components/mix-list-cell';
	import {
		doGet,
	} from '@/common/util.js'
	export default {
		components: {
			listCell,
			zyworkIcon
		},
		data() {
			return {
				userWallet: {},
				userWalletUrl: '/user-wallet/user/one',
				available:0,
				code:0,
			}
		},
		onLoad(options) {
			if(options.code){
				this.code = parseInt(options.code)
			}
		},
		onShow() {
			this.loadWalletInfo();
		},
 		methods: {
			loadAvailableBalance() {
				doGet('/withdraw/user/available', {}, {}, true).then(response => {
					let [error, res] = response
					if (res.data.code === ResponseStatus.OK) {
						this.available = parseFloat(res.data.data).toFixed(2)
					}
				}).catch(error => {
					console.log(error)
					showInfoToast('网络开小差，请稍候再试')
				})
			},
			/**
			 * 获取钱包信息
			 */
			loadWalletInfo() {
				doGet(this.userWalletUrl, {}, {}, true).then(response => {
					let [error, res] = response;
					if (res.data.code === ResponseStatus.OK) {
						this.userWallet = res.data.data;
						this.loadAvailableBalance()
					} else {
						showInfoToast(res.data.message);
					}
				}).catch(err => {
					console.log(err)
				})
			},
			toWithdraw() {
				let wallet = JSON.stringify(this.userWallet)
				uni.navigateTo({
					url: `/pages/wallet/withdraw?userWallet=${wallet}`
				})
			},
			toWithdrawList() {
				uni.navigateTo({
					url: '/pages/wallet/withdraw-list'
				})
			}
		}
	}
</script>

<style lang="scss">
	@import '@/common/zywork-main.scss';
	.zy-add-btn{
		background-color: #00AA7F;
		box-shadow: 1px 2px 5px rgba(0, 170, 127, 0.4);
	}
	.zy-head {
		padding: 10upx 0upx;
		margin-top: 20upx;
		background: #FFF;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
	}
	.zy-head-title {
		border-left: 5px solid #00aa7f;
		padding-left: 20upx;
		margin-left: 20upx;
		font-size: 28upx;
	}
	.zy-head-extra {
		padding-right: 10upx;
		font-sise: 24upx;
		color: #00aa7f;
	}
	
	.list-cell-section {
		margin-top: 20upx;
		background: #fff;
		border-radius: 10upx;
	}
</style>
